package com.fesine.learn.controller;

import com.fesine.commons.util.CheckCodeCreateUtil;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;


/**
 * Created by Administrator on 2017/4/15.
 */
@Controller
@RequestMapping("/images")
public class CaptchaImageCreateController {
    private static final Logger logger = Logger.getLogger(CaptchaImageCreateController.class);

    @RequestMapping("/createCode")
    public void createCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession(false);
        if ( session == null) {
            session = request.getSession();
        }
            String token = CheckCodeCreateUtil.createCode(response);
            session.setAttribute("captchaToken",token);
            UserInfoController.initTime = System.currentTimeMillis();
            logger.info("当前的sessionID="+session.getId()+",验证码="+token);


    }
}
